<?php
namespace app\web\controller;
use \think\Controller;
use app\web\model\Web;
use think\Db;

class Webs extends Controller
{

    function _initialize()
    {
        //站点配置
        $this->assign('site',getSite());
        //金融网产链接
        $this->assign('bank_links',getlinks(7));
    }
    //首页 渲染
    function index()
    {
        $model = new Web();

//        dump($model->getImageNews());
//
        $this->assign('moduleSlider',$model->getSlider());       //轮播图
        $this->assign('moduleImageNews',$model->getImageNews());   //图片新闻
        $this->assign('moduleMarket',$model->getArticle(28,7));   //市场动态
        $this->assign('moduleQuotation',$model->getArticle(27));   //行情资讯
        $this->assign('moduleNoticle',$model->getArticle(29,8));   //公告
//金融网产链接
        $this->assign('friendLinks',getlinks(8));
        return $this->fetch();
    }

    //列表页面
    function lists ($id){
        if(!intval($id) || !isCate($id)){
            $this->error('找不到页面');
        }
        $model = new Web();
        $this->assign('cate',$model->getCate($id));         //分类信息
        $this->assign('list',$model->getCatelist($id));     //分类列表分页数据
        return $this->fetch();
    }

    //内容页面
    function read($id){
        if(!intval($id) || !isArticle($id)){
            $this->error('找不到页面');
        }
        $model      = new Web();
        $article    = $model->getArticleOne($id);

        $this->assign('cate',$model->getCate($article['pid']));
        $this->assign('articleSimilar',$model->getSimilarArticle($id));
        $this->assign('article',$article);
        return $this->fetch();
    }

    //下载中心
    function down() {
        return $this->fetch();
    }

    //栏目 $id category id
    function channel($id) {

        $cate       = Db::name('category')->where('pid',$id)->find();
        $parent     = null;
        $soncate    = null;
        $noparent   = true;     //没有父级
        if(!$cate){
            return $this->error();
        }
        //如果有父级
        if($cate['parent_id']){
            $parent     = Db::name('category')->where('pid',$cate['parent_id'])->find();
            $soncate    = Db::name('category')->where('parent_id','in',$parent['pid'])->select();   //同级
            $noparent = false;
        }else{
            $parent = $cate;
        }

        //如果没有父级，那么查找子级
        if(!$soncate){
            $soncate = Db::name('category')->where('parent_id','in',$id)->select();            //子级
        }


        $this->assign('noparent',$noparent);            //确认是否存在父级，判定是否渲染子级第一个
        $this->assign('cate',$cate);
        $this->assign('parent',$parent);
        $this->assign('soncate',$soncate);
        return $this->fetch();
    }

    //行情中心
    function market() {
        return $this->fetch();
    }

}
